package com.dodol.util;

import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
import org.testng.Reporter;

/**
 * @Auther: 80736
 * @Date: 2018/9/6 16:27
 * @Description: 用例重跑机制
 */
public class TestNgRetry implements IRetryAnalyzer {
    private int retryCount = 1;
    private static final int maxRetryCount = 1;

    public boolean retry(ITestResult iTestResult) {
        System.out.println("第" + retryCount + "次重新执行");

        if (retryCount <= maxRetryCount) {
            String message = "Retry for [" + iTestResult.getName() + "] on class [" + iTestResult.getTestClass().getName() + "] Retry "
                    + retryCount + " times";
            Reporter.log(message);
            Reporter.setCurrentTestResult(iTestResult);
            Reporter.log("RunCount=" + (retryCount + 1));

            retryCount++;
            return true;
        }
        return false;
    }
}
